<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Gass recruit Class
 *
 * 该类作为处理招生活动访问的控制类
 * @author Jason Chan
 */ 
class Gass_recruit extends CI_Controller {

   function __construct() 
   {
    parent::__construct();
		
		 // Load required CI libraries and helpers.
		 $this->load->database();
		 $this->load->library('session');
 		 $this->load->helper('url');
 		 $this->load->helper('form');

  	 // It is used as a global that is accessible via both models and both libraries, without it, flexi auth will not work.
		 $this->auth = new stdClass;

		 // Load 'standard' flexi auth library by default.
		 $this->load->library('flexi_auth');	
		
		 //获取所需的配置数据
     $this->config->load('gass_conf');
		 // Check user is logged in via either password or 'Remember me'.
		 // Note: Allow access to logged out users that are attempting to validate a change of their email address via the 'update_email' page/method.
		 if (! $this->flexi_auth->is_logged_in())
		 {
			// Set a custom error message.
			$this->flexi_auth->set_error_message('必须登录才能访问这个部分！', TRUE);
			$this->session->set_flashdata('message', $this->flexi_auth->get_messages());
			redirect('gass_auth');
		 }
		 // Note: This is only included to create base urls for purposes of this demo only and are not necessarily considered as 'Best practice'.
		 $this->load->vars('base_url', $this->config->item('base_url'));
		 $this->load->vars('includes_dir', $this->config->item('includes_dir'));
		 $this->load->vars('current_url', $this->uri->uri_to_assoc(1));
		 // Define a global variable to store data that is then used by the end view page.
		 $this->data = null;
		 //$this->output->enable_profiler(TRUE);
	 }
 	/**
 	 * 招生活动一览的页面数据聚合
 	 *   
 	 * 研招办老师通过这个部分来生成招生宣传会所对应的验证码
 	 * 可添加、可删除、不能修改；时间过了就过期
 	 */
	function manage_recruit()
	{
	  $this->load->model('gass_recruit_model');
	  if (! $this->flexi_auth->is_privileged('recruit_m'))
	  {
		  $this->session->set_flashdata('message', '<p class="error_msg">您没有浏览、操作招生宣传活动的权限，请与系统管理员联系！</p>');
      redirect('gass_auth_teachers');
	  }
		if ($this->input->post('search_submit')&&$this->input->post('search_key_words')) 
		{
			$search_query = str_replace(' ','-',$this->input->post('search_key_words'));
		  redirect('gass_recruit/manage_recruit/search_key_words/'.$search_query.'/page/');
		}else if ($this->input->post('update_recruits')) {
			$this->gass_recruit_model->update_recruit_activities();
		}
		$this->gass_recruit_model->get_recruit_activities_list();
		
	  $this->data['message'] = (! isset($this->data['message'])) ? $this->session->flashdata('message') : $this->data['message'];		
          // 对系统报错信息（p标签包裹的数据）进行重新处理；        
          if (!empty($this->data['message']))
          {
              $this->data['alert_message'] = $this->gass_global_model->get_alert_message($this->data['message']);   
          } 
	  $this->load->view('t_recruit_search_view', $this->data);
	}	
 	/**
 	 * 新增招生活动的页面数据聚合
 	 *
 	 * 研招办老师通过这个部分来生成招生活动对应的招生码
 	 */
  function add_new_recruit(){
		//检查用户是否拥有访问权限
		if (! $this->flexi_auth->is_privileged('recruit_m')){
			$this->session->set_flashdata('message', '<p class="error_msg">您没有新增招生宣传活动的权限，请与系统管理员联系！</p>');
      redirect('gass_auth_teachers');
        }
   	if ($this->input->post('submit1')){
	    $this->load->model('gass_recruit_model');
	    $this->gass_recruit_model->add_new_recruit();
   	}
	  $this->data['message'] = (! isset($this->data['message'])) ? $this->session->flashdata('message') : $this->data['message'];		
          // 对系统报错信息（p标签包裹的数据）进行重新处理；        
          if (!empty($this->data['message']))
          {
              $this->data['alert_message'] = $this->gass_global_model->get_alert_message($this->data['message']);   
          } 
	  $this->load->view('new_recruit_view', $this->data);
	}	 
}
